using System;

namespace Threading
{
    public class WorkItem<TWorkItemState>
    {
        public bool IsCanceled
        {
            get; private set;
        }
    
        public WorkItem(Action<TWorkItemState> workMethod, TWorkItemState state)
        {
            this.WorkerId = Guid.NewGuid();
            this.WorkMethod = workMethod;
            this.State = state;
        }

        public bool ThereWereErrors { get; set; }
        public Exception LastException
        {
            get;
            set;
        }

        public bool IsFinished
        {
            get; set;
        }

        public bool IsStarted
        {
            get; set;
        }

        public Guid WorkerId
        {
            get; private set;
        }

        public Action<TWorkItemState> WorkMethod { get; set; }

        public TWorkItemState State
        {
            get; private set;
        }
        
        public void Cancel()
        {
            this.IsCanceled = true;
        }
    }
}